package ${packagePath}.resource;

import cn.easybuild.pojo.DataSet;
import net.sinedu.company.bases.ResponseObject;
import net.sinedu.company.bases.ResponseObjectUtil;
import net.sinedu.company.bases.rs.SpBaseResource;
import ${packagePath}.${className};
import ${packagePath}.${className}QueryParam;
import ${packagePath}.service.${className}Service;
import net.sinedu.foundation.core.service.model.Model;

import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.BeanParam;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

/**
 * Created by ${author} on ${datetime}.
 */
@Named
@Path(${className}SpResource.MODULE_NAME)
public class ${className}SpResource extends SpBaseResource {

  public static final String MODULE_NAME = BASE_URI_ADMIN + "/${pathName}";

  @Inject
  private ${className}Service ${classname}Service;

  /**
   * 列表
   */
  @GET
  public ResponseObject list(@BeanParam ${className}QueryParam queryParam) {
    DataSet<${className}> dataSet = ${classname}Service.query${className}ByParam(queryParam);

    return ResponseObjectUtil.responseWithRecordSet(dataSet);
  }

  /**
   * 保存
   */
  @POST
  public ResponseObject save(${className} entity) {
    ${classname}Service.save(entity);
    return ResponseObject.success();
  }

  /**
   * 更新
   */
  @PUT
  public ResponseObject update(${className} entity) {
    ${classname}Service.update(entity);
    return ResponseObject.success();
  }

  /**
   * 获取详情
   */
  @GET
  @Path("/{id}")
  public Model detail(@PathParam("id") String id) {
    ${className} entity = ${classname}Service.get(id);
    if (entity != null ) {
      Model model = Model.of(entity);
      return model;
    }
    return null;
  }

  /**
   * 删除
   */
  @DELETE
  @Path("/{id}")
  public ResponseObject delete(@PathParam("id") String id) {
    ${classname}Service.delete(id);
    return ResponseObject.success();
  }
}
